import {getAppEnvConfig} from '@/utils/env';
import pca from '@/api/pca.json';

import _douyin from '@/views/cashier/img/douyin.png';
import _mtdp from '@/views/cashier/img/mtdp.png';
import _wechat from '@/views/cashier/img/wechat.png';
import _alipay from '@/views/cashier/img/alipay.png';
import _koubei from '@/views/cashier/img/koubei.png';

const {VITE_GLOB_OSS_URL} = getAppEnvConfig();

export function OSS_FILE_URL(src) {
  src = src?.toString()?.trim() || '';

  if (src.startsWith('http://') || src.startsWith('https://')) {
    return src;
  }

  if (src.startsWith('/')) {
    return VITE_GLOB_OSS_URL + src;
  }

  return src;
}

export function OSS_IMG_URL(src, tacitly) {
  return OSS_FILE_URL(src) || tacitly || imgErrSrc;
}

export const staffRole = [
  {
    value: 'G001',
    label: '店长',
  },
  {
    value: 'G010',
    label: '美容师',
  },
];

export const staffStatus = [
  {
    value: 1,
    label: '在职',
  },
  {
    value: 2,
    label: '离职',
  },
];

export const storeBooking = [
  {
    value: '0',
    label: '不可预约',
  },
  {
    value: '1',
    label: '可预约',
  },
];

export const roomStatus = [
  {
    value: 1,
    label: '正常',
  },
  {
    value: 2,
    label: '维护',
  },
];

export const roomPeople = [
  {
    value: 1,
    label: '1人间',
  },
  {
    value: 2,
    label: '2人间',
  },
  {
    value: 3,
    label: '3人间',
  },
  {
    value: 4,
    label: '4人间',
  },
  {
    value: 5,
    label: '5人间',
  },
  {
    value: 6,
    label: '6人间',
  },
];

export const weekList = [
  {
    value: 1,
    label: '周一',
  },
  {
    value: 2,
    label: '周二',
  },
  {
    value: 3,
    label: '周三',
  },
  {
    value: 4,
    label: '周四',
  },
  {
    value: 5,
    label: '周五',
  },
  {
    value: 6,
    label: '周六',
  },
  {
    value: 7,
    label: '周日',
  },
];

export const platformType = [
  {
    value: 'tmall',
    label: '天猫',
  },
  {
    value: 'koubei',
    label: '口碑',
  },
  {
    value: 'meituan',
    label: '美团',
  },
  {
    value: 'douyin',
    label: '抖音',
  },
  {
    value: 'alipay',
    label: '支付宝',
  },
  {
    value: 'wechat',
    label: '小程序',
  },
];

export const proCategoryType = [
  {
    value: 'P',
    label: '居家产品',
  },
  {
    value: 'S',
    label: '疗程服务',
  },
];

export const proCategoryType2 = [
  {
    value: 'P',
    label: '居家产品',
  },
  {
    value: 'S',
    label: '疗程服务',
  },

  {
    value: 'C',
    label: '卡项',
  },
];

export const proCategoryType3 = [
  {
    value: 'V',
    label: '客户权益',
  },

  {
    value: 'P',
    label: '居家产品',
  },
  {
    value: 'S',
    label: '疗程服务',
  },

  {
    value: 'C',
    label: '卡项',
  },
];

export const proSource = [
  {
    value: 1,
    label: '选用',
  },
  {
    value: 2,
    label: '自建',
  },
];

export const proCategoryStatus = [
  {
    value: 1,
    label: '启用',
  },
  {
    value: 2,
    label: '禁用',
  },
];

export const proSelectStatus = [
  {
    value: 1,
    label: '已选用',
  },
  {
    value: 0,
    label: '未选用',
  },
];

export const proStatus = [
  {
    value: 1,
    label: '在售',
  },
  {
    value: 0,
    label: '停售',
  },
];

export const proCardType = [
  {
    value: '200',
    label: '次卡',
    children: [
      {
        value: '201',
        label: '有限次卡',
        desc: '支持创建多个服务集合的有限次数的次卡',
      },
      {
        value: '202',
        label: '不限次卡',
        desc: '支持创建多个服务集合且不限次数的月卡/季卡/年卡',
      },
      {
        value: '203',
        label: '通卡',
        desc: '设置一个总次数，客户可以在次数内消费卡中任意项目',
      },
    ],
  },
  {
    value: '100',
    label: '金额卡',
    children: [
      {
        value: '101',
        label: '金额卡',
      },
    ],
  },
];

export const proValidType = [
  {
    value: '10',
    label: '购买时生效',
  },
  {
    value: '20',
    label: '首次消费时生效',
  },
  {
    value: '30',
    label: '固定有效期',
  },
  {
    value: '40',
    label: '永久有效',
  },
];

export const proValidDateUnit = [
  {
    value: '年',
    label: '年',
  },
  {
    value: '月',
    label: '月',
  },
  {
    value: '日',
    label: '日',
  },
];

export const proConsumeType = [
  {
    value: 1,
    label: '先消耗本金再消耗赠金',
  },
  {
    value: 2,
    label: '先消耗赠金再消耗本金',
  },
];

//进货单位
export const proPurUnit = [
  {
    value: '套',
    label: '套',
  },
  {
    value: '瓶',
    label: '瓶',
  },
  {
    value: '盒',
    label: '盒',
  },
  {
    value: '支',
    label: '支',
  },
  {
    value: '罐',
    label: '罐',
  },
  {
    value: '箱',
    label: '箱',
  },
];

//售卖单位
export const proSaleUnit = [
  {
    value: '套',
    label: '套',
  },
  {
    value: '瓶',
    label: '瓶',
  },
  {
    value: '盒',
    label: '盒',
  },
  {
    value: '支',
    label: '支',
  },
  {
    value: '罐',
    label: '罐',
  },
  {
    value: '箱',
    label: '箱',
  },
];

//消耗单位
export const proCsmUnit = [
  {
    value: '片',
    label: '片',
  },
  {
    value: 'ML',
    label: 'ML',
  },
  {
    value: '次',
    label: '次',
  },
  {
    value: 'g',
    label: 'g',
  },
];

export const stockStatus = [
  {
    value: 1,
    label: '充足',
  },
  {
    value: 2,
    label: '不足',
  },
];

export const stockType = [
  {
    value: 'O',
    label: '门店自有',
  },
  {
    value: 'S',
    label: '客户寄存',
  },
];

//门店-变更类型
export const moveTypeO = [
  {
    value: 'S',
    label: '商品入库',
  },
  {
    value: 'D',
    label: '商品出库',
  },
];

export const moveTypeCodeList = [
  {
    value: 'S01',
    label: '采购入库',
    category: 'S',
  },
  {
    value: 'S02',
    label: '退货入库',
    category: 'S',
  },
  {
    value: 'S03',
    label: '调拨入库',
    category: 'S',
  },
  {
    value: 'S04',
    label: '盘盈入库',
    category: 'S',
  },
  {
    value: 'S05',
    label: '其他入库',
    category: 'S',
  },
  {
    value: 'S06',
    label: '寄存入库',
    category: 'S',
  },
  {
    value: 'D01',
    label: '销售出库',
    category: 'D',
  },
  {
    value: 'D02',
    label: '盘亏出库',
    category: 'D',
  },
  {
    value: 'D03',
    label: '领用出库',
    category: 'D',
  },
  {
    value: 'D04',
    label: '调拨出库',
    category: 'D',
  },
  {
    value: 'D05',
    label: '其他出库',
    category: 'D',
  },
  {
    value: 'D06',
    label: '配料出库',
    category: 'D',
  },
  {
    value: 'D07',
    label: '寄存领用出库',
    category: 'D',
  },

  {
    value: 'D08',
    label: '寄存消耗出库',
    category: 'D',
  },
];

export const moveTypeCodeList2 = [
  {
    value: 'S06',
    label: '寄存入库',
    category: 'S',
  },
  {
    value: 'D07',
    label: '寄存领用出库',
    category: 'D',
  },
  {
    value: 'D08',
    label: '寄存消耗出库',
    category: 'D',
  },
];

export const arrivalTimeList = [
  {
    value: 1,
    label: '1个月未到店',
  },
  {
    value: 2,
    label: '2个月未到店',
  },
  {
    value: 3,
    label: '3个月未到店',
  },
  {
    value: 6,
    label: '半年未到店',
  },
];

export const memberTypeList = [
  {
    value: 1,
    label: '新客',
  },
  {
    value: 2,
    label: '体验客',
  },
  {
    value: 3,
    label: '会员',
  },
];

export const memberSources = [
  {
    value: 1,
    label: '散客',
  },
  {
    value: 2,
    label: '抖音',
  },
  {
    value: 3,
    label: '美团/点评',
  },
  {
    value: 4,
    label: '老带新',
  },
  {
    value: 5,
    label: '客户小程序',
  },
  {
    value: 6,
    label: '支付宝',
  },
];

export const birthdayTimeList = [
  {
    value: 0,
    label: '当天生日',
  },
  {
    value: 1,
    label: '近三天生日',
  },
  {
    value: 2,
    label: '近一周生日',
  },
  {
    value: 3,
    label: '近三周生日',
  },
  {
    value: 4,
    label: '近一个月生日',
  },
];

export const birthdayTypes = [
  {
    value: 1,
    label: '阳历',
    children: [...birthdayTimeList],
  },
  {
    value: 2,
    label: '阴历',
    children: [...birthdayTimeList],
  },
];

export const marrys = [
  {
    value: 1,
    label: '已婚',
  },
  {
    value: 2,
    label: '未婚',
  },
  {
    value: 0,
    label: '保密',
  },
];

export const skinConditions = [
  {
    value: '无过敏史',
    label: '无过敏史',
  },
  {
    value: '化妆品过敏',
    label: '化妆品过敏',
  },
  {
    value: '接触性过敏',
    label: '接触性过敏',
  },
  {
    value: '季节性过敏',
    label: '季节性过敏',
  },
  {
    value: '香料过敏',
    label: '香料过敏',
  },
];

export const allergys = [
  {
    value: '无过敏史',
    label: '无过敏史',
  },
  {
    value: '化妆品过敏',
    label: '化妆品过敏',
  },
  {
    value: '接触性过敏',
    label: '接触性过敏',
  },
  {
    value: '季节性过敏',
    label: '季节性过敏',
  },
  {
    value: '香料过敏',
    label: '香料过敏',
  },
];

export const skincareHabits = [
  {
    value: '清洁',
    label: '清洁',
  },
  {
    value: '保湿',
    label: '保湿',
  },
  {
    value: '精华',
    label: '精华',
  },
  {
    value: '乳霜',
    label: '乳霜',
  },
  {
    value: '防晒',
    label: '防晒',
  },
];

export const skincareNeeds = [
  {
    value: '补水',
    label: '补水',
  },
  {
    value: '美白',
    label: '美白',
  },
  {
    value: '抗衰',
    label: '抗衰',
  },
  {
    value: '修护',
    label: '修护',
  },
];

export const pastBeautyHistorys = [
  {
    value: '无',
    label: '无',
  },
  {
    value: '其他生美机构',
    label: '其他生美机构',
  },
  {
    value: '光电医美',
    label: '光电医美',
  },
  {
    value: '整形医美',
    label: '整形医美',
  },
];

export const cashPayCodes = [
  {
    value: 'cash',
    label: '现金',
  },
  {
    value: 'cash_wechat',
    label: '微信',
  },
  {
    value: 'cash_alipay',
    label: '支付宝',
  },
  {
    value: 'cash_bank_card',
    label: '银联',
  },
];

export const verifyTypes = [
  {
    value: '2',
    label: '抖音',
    icon: _douyin,
    key: 'douyin',
  },
  {
    value: '3',
    label: '美团/点评',
    icon: _mtdp,
    key: 'meituan',
  },
  {
    value: '6',
    label: '支付宝',
    icon: _alipay,
    key: 'alipay',
  },
  {
    value: '7',
    label: '口碑',
    icon: _koubei,
    key: 'koubei',
  },
  {
    value: '5',
    label: '客户小程序',
    icon: _wechat,
    key: 'wechat',
  },
];



export const verifyTypesList = [
  {
    value: 'douyin',
    label: '抖音',
    icon: _douyin,
    key: 'douyin',
  },
  {
    value: 'meituan',
    label: '美团/点评',
    icon: _mtdp,
    key: 'meituan',
  },
  {
    value: 'alipay',
    label: '支付宝',
    icon: _alipay,
    key: 'alipay',
  },
  {
    value: 'koubei',
    label: '口碑',
    icon: _koubei,
    key: 'koubei',
  },
  {
    value: 'wechat',
    label: '客户小程序',
    icon: _wechat,
    key: 'wechat',
  },
];


export const orderStatus = [
  {
    value: 0,
    label: '未确认',
  },
  {
    value: 1,
    label: '已确认',
  },
];


export const repaymentStatus = [
  {
    value: 0,
    label: '待还款',
  },
  {
    value: 1,
    label: '已还款',
  },
];

export const itemGoodsType = [
  {
    value: "1",
    label: '商品',
  },
  {
    value: "2",
    label: '疗程',
  },
  {
    value: "3",
    label: '券卡',
  },
];
export const itemGoodsTDType = [
  {
    value: "3",
    label: '退卡',
  },
  {
    value: "1",
    label: '退款',
  },
];

export const chargebackType = [
  {
    value: "1",
    label: '退卡',
  },
  {
    value: "2",
    label: '退款',
  }
];

export const ocbList = [
  {
    value: "1",
    label: '卡耗明细',
  },
  {
    value: "2",
    label: '购买权益',
  },
  {
    value: "3",
    label: '赠送权益',
  },
];

export const backList=[
  {
    value: "1",
    label: '未退回',
  },
  {
    value: "2",
    label: '已退回',
  },
];

export const refundList=[
  {
    value: "1",
    label: '退卡次数',
  },
  {
    value: "2",
    label: '退现金',
  },
];

export const refundList2=[
  {
    value: "1",
    label: '退卡余额',
  },
  {
    value: "2",
    label: '退现金',
  },
];

export function getChildren(list, value) {
  return list?.find((o) => o.value?.toString() === value?.toString())?.children ?? null;
}

export function getLabel(list, value) {
  return list?.find((o) => o.value?.toString() === value?.toString())?.label ?? null;
}

export function getChildrenLabel(list, value1, value2) {
  return getLabel(getChildren(list, value1), value2);
}

/**
 * 解析省市区
 */
export function parsePca(text) {
  const result = [];

  for (const p of pca) {
    if (text.startsWith(p.name)) {
      result.push(p.code);

      text = text.substring(p.name.length);
      let c = p.children.find((z) => text.startsWith(z.name));

      if (c) {
        text = text.substring(c.name.length);
      } else {
        c = p.children.find((z) => z.name === '市辖区');
      }

      if (!c) {
        continue;
      }

      result.push(c.code);

      for (const a of c.children) {
        if (text.startsWith(a.name)) {
          result.push(a.code);
        }
      }
    }
  }

  return result;
}

/**
 * 格式化省市区
 */
export function formatPca(list) {
  const result = [];

  for (const p of pca) {
    if (p.code === list[0]) {
      result.push(p.name);

      for (const c of p.children) {
        if (c.code === list[1]) {
          result.push(c.name);

          for (const a of c.children) {
            if (a.code === list[2]) {
              result.push(a.name);
            }
          }
        }
      }
    }
  }

  return result.join('');
}

export const imgErrSrc =
  '';
